//
//  UIBarButtonItem+State.m
//  可拖拽的view
//
//  Created by LeungChaos on 16/4/19.
//  Copyright © 2016年 liang. All rights reserved.
//

#import "UIBarButtonItem+State.h"

@implementation UIBarButtonItem (State)

+ (instancetype)barButtonItemWithNormalImage:(UIImage *)image HighlightedImage:(UIImage *)highlightedImage target:(id)tg action:(SEL)action
{
    UIButton *btn = [[UIButton alloc]init];
    [btn setImage:image forState:UIControlStateNormal];
    [btn setImage:highlightedImage forState:UIControlStateHighlighted];
    [btn sizeToFit];
    [btn addTarget:tg action:action forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem *barItem = [[UIBarButtonItem alloc]initWithCustomView:btn];
    
    return barItem;
}

+ (instancetype)barButtonItemWithNormalImage:(UIImage *)image selectedImage:(UIImage *)selectedImage target:(id)tg action:(SEL)action
{
    UIButton *btn = [[UIButton alloc]init];
    [btn setImage:image forState:UIControlStateNormal];
    [btn setImage:selectedImage forState:UIControlStateSelected];
    [btn sizeToFit];
    [btn addTarget:tg action:action forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem *barItem = [[UIBarButtonItem alloc]initWithCustomView:btn];
    
    return barItem;
}

+ (instancetype)barButtonItemWithTitle:(NSString *)title normalImage:(UIImage *)image HighlightedImage:(UIImage *)highlightedImage target:(id)tg action:(SEL)action
{
    
    UIButton *btn = [[UIButton alloc]init];
    [btn setImage:image forState:UIControlStateNormal];
    [btn setImage:highlightedImage forState:UIControlStateHighlighted];
    
    [btn setTitle:title forState:UIControlStateNormal];
    
    // 设置文字的颜色
    [btn setTitleColor:[UIColor darkGrayColor] forState:UIControlStateNormal];
    [btn setTitleColor:[UIColor redColor] forState:UIControlStateHighlighted];
    
    [btn sizeToFit];
    [btn addTarget:tg action:action forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem *barItem = [[UIBarButtonItem alloc]initWithCustomView:btn];
    
    return barItem;
}


@end
